﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization.Json;

namespace G.WeiBo.WebAPI.Parser
{
    public class JsonParser
    {
        public T Parse<T>(string body)
        {
            return (T)Parse(typeof(T), body);
        }
        public object Parse(Type type, string body)
        {
            DataContractJsonSerializer se = new DataContractJsonSerializer(type);
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(body)))
            {
                return se.ReadObject(stream);
            }
        }

    }
}
